package behavioral.templateMethod;

import behavioral.templateMethod.custom.AppleJuice;
import behavioral.templateMethod.custom.WatermelonJuice;
import behavioral.templateMethod.java.Person;

import java.util.Arrays;

/**
 * 模板方法模式
 * 定义一个操作中的算法骨架，将算法的一些步骤延迟到子类中，使得子类在可以不改变该算法结构的情况下重定义该算法的某些特定步骤。
 */
public class Main {
    public static void main(String[] args) {
        System.out.println(" = = 制作苹果汁 = = ");
        AppleJuice appleJuice = new AppleJuice();
        appleJuice.make();

        System.out.println(" = = 制作西瓜汁 = = ");
        WatermelonJuice watermelonJuice = new WatermelonJuice();
        watermelonJuice.make();

        System.out.println(" = = 排序 = = ");
        Person[] persons = new Person[]{new Person("小明", 150),new Person("小亮", 120),new Person("小红", 130)};
        Arrays.sort(persons); // 模板方法
        for (int i = 0; i < persons.length ; i++) {
            Person p = persons[i];
            System.out.println("序号：" + (i+1) + "，" + p.getName() + " 身高: " + p.getHeight());
        }
    }
}
